package tech.aistar.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tech.aistar.entity.Point;

/**
 * Created by Administrator on 2019/10/14.
 */
public interface PointMapper {
    //查询所有点赞数
    @Select("select count(*) from point where post_id = #{postId}")
    Long findPointCount(Integer postId);

    //第一次点赞
    @Insert("insert into point(id,user_id,type,post_id,status,time,del_time) values (#{id},#{user_id},#{type},#{post_id},#{status},#{time},#{del_time})")
    void addPoint(Point point);

    /**
     * 帖子点赞状态变为真
     */
    @Update("update point set status = 0 where user_id = #{arg0} and post_id = #{arg1}")
    void updatestatusTo0(Integer userId,Integer postId);

    /**
     * 帖子取消点赞一次
     */
    @Update("update point set status = 1 where user_id = #{arg0} and post_id = #{arg1}")
    void updatestatusTo1(Integer userId,Integer postId);

    /**
     * 根据用户id和帖子id查询数据
     */
    @Select("select * from point where user_id = #{arg0} and post_id = #{arg1}")
    Point findPointByUidAndStraId(Integer userId, Integer postId);

    /**
     * 查询一个帖子的点赞数
     */
    @Select("select count(*) from point where type = 1 and status = 0 and post_id = #{value}")
    int findStarLikesCount(Integer postId);


}
